<?php

/**
 * This is the model class for table "sys_serial_products".
 *
 * The followings are the available columns in table 'sys_serial_products':
 * @property string $serial_products_id
 * @property string $serial_products_pin
 * @property string $serial_products_products_category_id
 * @property string $serial_products_create_datetime
 * @property string $serial_products_active_datetime
 * @property string $serial_products_is_buyed
 * @property string $serial_products_is_active
 * @property string $serial_products_is_used
 */
class sys_serial_products extends CActiveRecord {

    public $serial_products_count;

    /**
     * Returns the static model of the specified AR class.
     * @return sys_serial_products the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'sys_serial_products';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('serial_products_id', 'length', 'max' => 16),
            array('serial_products_pin', 'length', 'max' => 50),
            array('serial_products_products_category_id', 'length', 'max' => 20),
            array('serial_products_is_buyed, serial_products_is_active, serial_products_is_used', 'length', 'max' => 1),
            array('serial_products_create_datetime, serial_products_active_datetime', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('serial_products_id, serial_products_pin, serial_products_products_category_id, serial_products_create_datetime, serial_products_active_datetime, serial_products_is_buyed, serial_products_is_active, serial_products_is_used', 'safe', 'on' => 'search'),
            array('serial_products_count', 'length', 'min' => 1, 'max' => 100, 'allowEmpty' => true, 'on' => 'update'),
            array('serial_products_count', 'length', 'min' => 1, 'max' => 100, 'allowEmpty' => false, 'on' => 'insert'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_serial_products_to_products_category' => array(self::BELONGS_TO, 'ecom_products_category', 'serial_products_products_category_id'),
            'rel_serial_products_to_serial_product_buyer' => array(self::HAS_ONE, 'sys_serial_products_buyer', 'serial_products_buyer_serial_products_id'),
            'rel_serial_products_to_serial_product_user' => array(self::HAS_ONE, 'sys_serial_products_user', 'serial_products_user_serial_products_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'serial_products_id' => 'Serial Products',
            'serial_products_pin' => 'PIN',
            'serial_products_products_category_id' => 'Products Category',
            'serial_products_create_datetime' => 'Serial Create Datetime',
            'serial_products_active_datetime' => 'Serial Active Datetime',
            'serial_products_is_buyed' => 'Serial Is Buyed',
            'serial_products_is_active' => 'Serial Is Active',
            'serial_products_is_used' => 'Serial Is Used',
            'serial_products_count' => 'Serial Count',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->addCondition('serial_products_products_category_id NOT IN (4)');

        $criteria->compare('serial_products_id', $this->serial_products_id, true);
        $criteria->compare('serial_products_pin', $this->serial_products_pin, true);
        $criteria->compare('serial_products_products_category_id', $this->serial_products_products_category_id, true);
        $criteria->compare('serial_products_create_datetime', $this->serial_products_create_datetime, true);
        $criteria->compare('serial_products_active_datetime', $this->serial_products_active_datetime, true);
        $criteria->compare('serial_products_is_buyed', $this->serial_products_is_buyed, true);
        $criteria->compare('serial_products_is_active', $this->serial_products_is_active, true);
        $criteria->compare('serial_products_is_used', $this->serial_products_is_used, true);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}